﻿using InnovaApp.Portals.MVC4Portal.Models.JSonModels;
using InnovaApp.Portals.MVC4Portal.Models.WebAPIModels.JSTO;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;
using System.Web.Security;

namespace InnovaApp.Portals.MVC4Portal.Controllers.WebAPIControllers.UserRegistration
{
    public class CheckEMailAvailabilityController : _WebAPIControllers_Base<CheckEMailAvailability_WebAPIModel>
    {
        protected static string eMethodBase = "InnovaApp.Portals.MVC4Portal.Controllers.WebAPIControllers.UserRegistration.CheckEMailAvailabilityController";
        /// <summary>
        /// HTTP Get
        /// </summary>
        /// <param name="language">The language.</param>
        /// <param name="model">The model.</param>
        /// <returns>HttpResponseMessage.</returns>
        public HttpResponseMessage Post(string language, CheckEMailAvailability_JSonModel model)
        {
            HttpResponseMessage toReturn;
            string eMethod = eMethodBase + ".Get";
            object eParameters = new { language = language, model = model };
            string userName = Membership.GetUserNameByEmail(model.emailaddress);
            ApiData.success = true;
            ApiData.isAvailable = string.IsNullOrEmpty(userName);
            toReturn = base.CreateResponse(HttpStatusCode.OK);
            return toReturn;
        }
    }
}
